﻿#include <QDebug>
#include "ToolBarJoystick.h"
#include "Joystick3D.h"

ToolBarJoystick::ToolBarJoystick(QWidget *parent)
    :QToolBar (parent)
{
    initContent();
    initConnection();
}

void ToolBarJoystick::attach(Joystick3D *joystick)
{

    joystick->enableSignal(true);
    joystick->enableButtonSignal(true);
    joystick->enableXYSignal(true);
    joystick->enableZSignal(true);
    bool a, b,c, d;
    joystick->signalEnableState(a, b, c, d);
    qDebug() << "a = " << a << ",b = " << b << ", c = " << c << ",d = " << d;
    actionJoystick->setChecked(a);
    actionXYEnable->setChecked(b);
    actionZEnable->setChecked(c);
    actionButtonsEnable->setChecked(d);

    connect(this, SIGNAL(enableSignal(bool)), joystick, SLOT(enableSignal(bool)));
    connect(this, SIGNAL(enableXYSignal(bool)), joystick, SLOT(enableXYSignal(bool)));
    connect(this, SIGNAL(enableZSignal(bool)), joystick, SLOT(enableZSignal(bool)));
    connect(this, SIGNAL(enableButtionSignal(bool)), joystick, SLOT(enableButtionSignal(bool)));
}

void ToolBarJoystick::initContent()
{
    setObjectName(QStringLiteral("ToolBarJoystick"));
    setWindowTitle("Joystick Toolbar");
    actionJoystick = new QAction(this);
    actionJoystick->setObjectName(QStringLiteral("actionJoystick"));
    actionJoystick->setCheckable(true);
    QIcon icon;
    icon.addFile(QStringLiteral(":/Joystick/res/Joystick256.png"), QSize(), QIcon::Normal, QIcon::Off);
    actionJoystick->setIcon(icon);
    addAction(actionJoystick);
    actionJoystick->setVisible(true);

    actionXYEnable = new QAction(this);
    actionXYEnable->setObjectName(QStringLiteral("actionXYEnable"));
    actionXYEnable->setCheckable(true);
    icon.addFile(QStringLiteral(":/Joystick/res/XY256.png"), QSize(), QIcon::Normal, QIcon::Off);
    actionXYEnable->setIcon(icon);
    addAction(actionXYEnable);
    actionXYEnable->setVisible(true);

    actionZEnable = new QAction(this);
    actionZEnable->setObjectName(QStringLiteral("actionZEnable"));
    actionZEnable->setCheckable(true);
    icon.addFile(QStringLiteral(":/Joystick/res/Z256.png"), QSize(), QIcon::Normal, QIcon::Off);
    actionZEnable->setIcon(icon);
    addAction(actionZEnable);
    actionZEnable->setVisible(true);

    actionButtonsEnable = new QAction(this);
    actionButtonsEnable->setObjectName(QStringLiteral("actionButtonsEnable"));
    actionButtonsEnable->setCheckable(true);
    icon.addFile(QStringLiteral(":/Joystick/res/Button256.png"), QSize(), QIcon::Normal, QIcon::Off);
    actionButtonsEnable->setIcon(icon);
    addAction(actionButtonsEnable);
    actionButtonsEnable->setVisible(true);


}
void ToolBarJoystick::initConnection()
{
    connect(actionJoystick, SIGNAL(triggered(bool)), this, SIGNAL(enableSignal(bool)));
    connect(actionXYEnable, SIGNAL(triggered(bool)), this, SIGNAL(enableXYSignal(bool)));
    connect(actionZEnable, SIGNAL(triggered(bool)), this, SIGNAL(enableZSignal(bool)));
    connect(actionButtonsEnable, SIGNAL(triggered(bool)), this, SIGNAL(enableButtionSignal(bool)));
}
